#ifndef MY_FILTER_H
#define MY_FILTER_H

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>

#define EPS 0.000001

// zero-phase filter
// pointer "x" points to a input sequence, pointer "y" an output sequence, xlen is the length of input sequence,
// pointer "a" points to the denominators of direct form ii transposed structure,
// pointer "b" the numerators of direct form ii transposed structure,
// nfilt is the maximum length of the denominators pointed by "a" and the numerators pointed by "b"
// add 0-value elements to the shorter one of arrays pointed by "a" and "b" respectively such that denominators and numerators have the same length
int filtfilt(double* x, double* y, int xlen, double* a, double* b, int nfilt);

//implementation of the filter with direct form ii transposed structure

//initial conditions: zi, a vector, its length == nfilt-1. ignored when zi==NULL
// pointer "x" points to a input sequence, pointer "y" an output sequence, xlen is the length of input sequence,
// pointer "a" points to the denominators of direct form ii transposed structure,
// pointer "b" the numerators of direct form ii transposed structure,
// nfilt is the maximum length of the denominators pointed by "a" and the numerators pointed by "b"
// add 0-value elements to the shorter one of arrays pointed by "a" and "b" respectively such that denominators and numerators have the same length
void filter(double* x, double* y, int xlen, double* a, double* b, int nfilt, double* zi);

//using Gauss-Jordan Method to solve the inverse of Matrix pointed by the pointer a
//the dimension of the matrix is n
int invMat(double *a, int n);

// Matrix Multiplication
// pointer "a" points to a matrix("m" x "n"),"b" a matrix ("n" x "k")
void mulMat(double *a,double *b,double *c,int m,int n,int k);

#endif
